//
//  UITextView+Category.m
//  VICategory
//
//  Created by MN on 2023/11/22.
//

#import "UITextView+Category.h"
#import <objc/runtime.h>

@implementation UITextView (Category)
- (NSString *)vi_placeholder{
    return objc_getAssociatedObject(self, @selector(vi_placeholder));
}
- (void)setVi_placeholder:(NSString *)vi_placeholder {
    objc_setAssociatedObject(self, @selector(vi_placeholder), vi_placeholder, OBJC_ASSOCIATION_COPY_NONATOMIC);
    [self updatePlaceholder];
}

- (NSString *)vi_placeholderLabel{
    return objc_getAssociatedObject(self, @selector(vi_placeholderLabel));
}
- (void)setVi_placeholderLabel:(UILabel *)vi_placeholderLabel {
    objc_setAssociatedObject(self, @selector(vi_placeholderLabel), vi_placeholderLabel, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (void)updatePlaceholder{
    if(!self.vi_placeholderLabel){
        self.vi_placeholderLabel = [[UILabel alloc]init];
        self.vi_placeholderLabel.text = @"请填写处理说明/备注原因（最多300个字）";
        self.vi_placeholderLabel.numberOfLines = 0;
        self.vi_placeholderLabel.textColor = UIColor.lightGrayColor;
        self.vi_placeholderLabel.font = [UIFont systemFontOfSize:14.f];
        [self.vi_placeholderLabel sizeToFit];
        [self addSubview:self.vi_placeholderLabel];
        self.vi_placeholderLabel.font = [UIFont systemFontOfSize:14];
        [self setValue:self.vi_placeholderLabel forKey:@"_placeholderLabel"];
    }
    self.vi_placeholderLabel.text = self.vi_placeholder;
}

@end
